<template>
  <div>
    <div class="title">留言板</div>
    <div class="body">
      <div class="content">
        <div class="zyz">留言内容：</div>
        <el-form :model="addForm" label-width="80px">
          <el-form-item label="">
            <el-input
              class="input"
              v-model="addForm.content"
              type="textarea"
              :rows="4"
              maxlength="50"
              placeholder="请输入内容"
            ></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="add">提交留言</el-button>
            <el-button type="">清空内容</el-button>
          </el-form-item>
          <el-input v-if="sss" v-model="addForm.id"></el-input>
        </el-form>
      </div>
      <div class="leave">
        <ul v-for="(item, index) in list" :key="index">
          <li>
            <span>用户名：</span>

            {{ item.username }}
          </li>
          <li>
            <span>留言内容：</span>

            {{ item.reply }}
          </li>
          <li>
            <span>回复内容:</span>

            {{ item.replyPicture }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      addForm:{
        id:window.sessionStorage.getItem("id"),
        content:null
      },
      list: "",
      sss:false
    };
  },
  methods: {
    async add() {
      console.log(this.addForm.content);
      let { data: res } = await this.$axios.post("/msgboard/add",this.addForm);
      console.log(res);
    },
    async getlist() {
      let { data: res } = await this.$axios.get("msgboard/getlist");
      console.log(res);
      this.list = res.data.list;
      console.log(this.list);
      console.log(window.sessionStorage.getItem("id"));
    },
  },
  created() {
    this.getlist();
  },
};
</script>

<style lang="scss" scoped>
.title {
  font-size: 40px;
  margin: 0 auto;
  text-align: center;
}
.content {
  width: 60%;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  background-color: rgb(242, 242, 240);
  .zyz {
    height: 100px;
    font-size: 20px;
    margin-top: 20px;
    margin-right: 20px;
    line-height: 100px;
  }
  form {
    width: 70%;
  }
}
.el-form-item {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px auto;
  button {
    margin-left: 30px;
  }
}
.input {
  width: 500px;
  height: 100px;
}
.leave {
  ul {
    width: 62%;
    margin: 40px auto;
    border-radius: 10px;
    background-color: rgb(136, 169, 214);
  }
  li {
    // border-radius:8px ;
    background-color: rgb(242, 242, 240);

    span {
      font-size: 20px;
      color: rgb(64, 158, 255);
    }
  }
}
</style>